package com.imagine.controller.stockinfo;

import com.imagine.entity.BaseResult;
import com.imagine.entity.Stock;
import com.imagine.service.StockService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.*;

import javax.jms.Queue;
import java.io.IOException;

/**
 * Created by liangyue on 2017/10/2.
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/stock")
public class StockController {
    @Autowired
    StockService stockService;

    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    Queue queue1;

    @ApiOperation(value="获得股票信息", notes="获得股票信息")
    @ApiImplicitParam(name = "code", value = "Code", required = true, dataType = "String",paramType = "path")
    @RequestMapping(value = "/info/{code}", method = RequestMethod.GET)
    public Stock getStockByCode(@PathVariable String code) throws IOException {
        return this.jmsMessagingTemplate.convertSendAndReceive(queue1,code, Stock.class);
    }


//    @ApiOperation(value="获得股票图", notes="获得股票图")
//    @ApiImplicitParam(name = "code", value = "Code", required = true, dataType = "String",paramType = "path")
//    @RequestMapping(value = "/image/{code}", method = RequestMethod.GET)
//    public BaseResult getStockImageByCode(@PathVariable String code) throws IOException {
//         return stockService.queryStockImage(code);
//    }

    @ResponseBody
    @ApiOperation(value="获得所有股票的实时情况", notes="获得所有股票的实时情况")
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public BaseResult getAllStockInfo() throws IOException {
        return stockService.queryAllStock();
    }


}
